<template>
	<view>
		    <form @submit.prevent="onSubmit" @reset="formReset">
			<view>
			  <view>施工单位:</view>
			  <input type="text" name="constructionUnit" v-model="formData.constructionUnit" placeholder="请输入施工单位" />
			</view>
			
			<view>
			  <view>施工地点:</view>
			  <input type="text" name="constructionLocation" v-model="formData.constructionLocation" placeholder="请输入施工地点" />
			</view>
			
			<view>
			  <view>工程名称:</view>
			  <input type="text" name="projectName" v-model="formData.projectName" placeholder="请输入工程名称" />
			</view>
			
			<view class="uni-title uni-common-pl" >盯岗时间:</view>
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						
					</view>
					<view class="uni-list-cell-db">
						<picker mode="date" :value="date" :start="startDate" :end="endDate"  @change="bindDateChange">
							<view class="uni-input">{{date}}</view>
						</picker>
					</view>
				</view>
			</view>
			
			<view>
			  <view>天气:</view>
			  <input type="text" name="weather" v-model="formData.weather" placeholder="请输入天气" />
			</view>
			
			<view>
			  <view>现场施工亮点及存在问题:</view>
			  <input type="text" name="highlightsProblemsOnSiteConstruction" v-model="formData.highlightsProblemsOnSiteConstruction" placeholder="请输入现场施工亮点及存在问题" />
			</view>
			
			<view>
			  <view>问题整改意见:</view>
			  <input type="text" name="problemRectificationOpinions" v-model="formData.problemRectificationOpinions" placeholder="请输入问题整改意见" />
			</view>
			
			<view>
			  <view>整改情况:</view>
			  <input type="text" name="rectificationSituation" v-model="formData.rectificationSituation" placeholder="请输入整改情况" />
			</view>
			
			<view>
			  <view>带班盯岗干部:</view>
			  <input type="text" name="monitoringLeader" v-model="formData.monitoringLeader" placeholder="请输入带班盯岗干部" />
			</view>
			
			<view>
			  <view>现场负责人（签字）:</view>
			  <input type="text" name="onsiteResponsibleBySignature" v-model="formData.onsiteResponsibleBySignature" placeholder="请输入现场负责人（签字）" />
			</view>
			
			<button form-type="submit" type="primary" style="margin: 10px;">提交</button>
			</form>
	</view>
</template>

<script>
	import axios from "axios"
	import { title } from "process";
	export default {
		data() {
			const currentDate = this.getDate({
			            format: true
			        })
			return {
				date: currentDate,
				formData: {
				  constructionUnit:"",
				  constructionLocation:'',
				  projectName: "",
				  dutyTime: "",
				  weather: "",
				  highlightsProblemsOnSiteConstruction: "",
				  problemRectificationOpinions: "",
				  rectificationSituation: "",
				  monitoringLeader: "",
				  onsiteResponsibleBySignature: "",
				},
			}
		},
		computed: {
		        startDate() {
		            return this.getDate('start');
		        },
		        endDate() {
		            return this.getDate('end');
		        }
		    },
		methods: {
			bindDateChange: function(e) {
				
			            this.date = e.detail.value
						this.formData.dutyTime = this.date
			        },
			onSubmit(e) {
			      e.preventDefault(); // 防止表单默认提交
				  console.log("test")
			      // console.log(e.target.detail.value);
			      // this.obj = e.target.detail.value;
				  axios.post("http://localhost:82/siteReviewRecord/management",this.formData)
				  .then((data)=>{
					  console.log(data)
					  uni.navigateTo({
					              url: '/pages/constructionprocess/constructionprocess?update6=true'
					            });
				  }).catch((err)=>{
					  console.log(err)
				  })
				  
			    },
			getDate(type) {
			            const date = new Date();
			            let year = date.getFullYear();
			            let month = date.getMonth() + 1;
			            let day = date.getDate();
			
			            if (type === 'start') {
			                year = year - 60;
			            } else if (type === 'end') {
			                year = year + 2;
			            }
			            month = month > 9 ? month : '0' + month;
			            day = day > 9 ? day : '0' + day;
			            return `${year}-${month}-${day}`;
			        }
		}
	}
</script>

<style>

</style>
